//
//  BKUserCodeFormat.m
//  bestkeep
//
//  Created by windCould on 16/12/13.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKUserCodeFormat.h"
#import "BKMyCommon.h"
@implementation BKUserCodeFormat

//判断字符串的是否为空
+(BOOL)parameterValueIsNotNilAndZeroLengthWithContentStr:(NSString *)contenStr
{
    if (IsNilString(contenStr)) {
        
        return NO;
    } else {
        
        return YES;
    }
    
}

//判断用户手机号的格式是否正确
+(BOOL)userMobileCodeOfBKPlatformatIsAdaptRequireWidthMobileNum:(NSString *)mobileNum
{
    NSString *predictStr =  @"^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))\\d{8}$";
    NSRegularExpression *regexCellphone = [NSRegularExpression regularExpressionWithPattern:predictStr options:0 error:nil];
    
    NSTextCheckingResult *isMatchCellphone = [regexCellphone firstMatchInString:mobileNum
                                                                        options:0
                                                                          range:NSMakeRange(0, [mobileNum length])];
    if (!isMatchCellphone) {
        
        return NO;
    } else {
        
        return YES;
    }
    
}

//判定密码的格式是否正确 提示语：@"请重新输入密码，英文或数字或 - _"
+(BOOL)userPwdCodeFormatIsRigthWithUserPwdStr:(NSString *)pwdStr
{
    NSString *passwordStandard = @"^[A-Za-z0-9_-]+$";
    
    NSRegularExpression *regexpasswordStandard = [NSRegularExpression regularExpressionWithPattern:passwordStandard options:0 error:nil];
    
    NSTextCheckingResult *isMatchpasswordStandard = [regexpasswordStandard firstMatchInString:pwdStr options:0 range:NSMakeRange(0, [pwdStr length])];
    
    if (!isMatchpasswordStandard) {
        
        return NO;
    } else {
        
        
        return YES;
    }
    
}

//判定密码是否含有空格
+(BOOL)userPwdIsContainSpaceWithPwdStr:(NSString *)pwdStr
{
    if ([pwdStr rangeOfString:@" "].location != NSNotFound) {
        
        return NO;
    }
   
    return YES;
}

//判定相应代码的位数
+(NSInteger)stringLengthIsRightWIthRequireMinLength:(NSInteger)minLength maxLength:(NSInteger)maxLength contentStr:(NSString *)contentStr
{
    if (contentStr.length > maxLength) {
        
        return maxLength;
    }
  
    if (contentStr.length < minLength) {
        
        return minLength;
    }
    
    return 1;
}

//身份证正则判断
+(BOOL) validateIdentityCard: (NSString *)identityCard
{
    
  /*  if (identityCard.length == 15) {
        
        regex2 = @"^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$";
    }else if (identityCard.length == 18){
        regex2 = @"^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$";
    }
    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
    return [identityCardPredicate evaluateWithObject:identityCard];
  */
    
    return [[self alloc] isValidCertifyID:identityCard];
}

//用户名正则判断
+(BOOL)isNameValid:(NSString *)name
{
    BOOL isValid = NO;
    
    if (name.length > 0)
    {
        for (NSInteger i=0; i<name.length; i++)
        {
            unichar chr = [name characterAtIndex:i];
            
            if (chr < 0x80)
            { //字符
                if (chr >= 'a' && chr <= 'z')
                {
                    isValid = YES;
                }
                else if (chr >= 'A' && chr <= 'Z')
                {
                    isValid = YES;
                }
                else if (chr >= '0' && chr <= '9')
                {
                    isValid = NO;
                }
                else if (chr == '-' || chr == '_')
                {
                    isValid = NO;
                }
                else
                {
                    isValid = NO;
                }
            }
            else if (chr >= 0x4e00 && chr < 0x9fa5)
            { //中文
                isValid = YES;
            }
            else
            { //无效字符
                isValid = NO;
            }
            
            if (!isValid)
            {
                break;
            }
        }
    }
    
    return isValid;
}

-(BOOL)isValidCertifyID:(NSString *)ID{
    BOOL isValid ;
    if (ID.length > 0) {
        for (NSInteger i=0; i<ID.length; i++) {
            unichar chr = [ID characterAtIndex:i];
            if (chr < 0x80) {
                if (chr == '&' || chr == '?' || chr == '=') {
                    return NO;
                }else if (chr >= 'a' && chr <= 'z')
                {
                    isValid = YES;
                }
                else if (chr >= 'A' && chr <= 'Z')
                {
                    isValid = YES;
                }
                else if (chr >= '0' && chr <= '9')
                {
                    isValid = YES;
                }else
                {
                    isValid = YES;
                }
            }
            
            if (!isValid)
            {
                break;
            }
        }
    }
    return isValid;
    
}

//判断是否超过一屏
+(BOOL)isOverWholeScreenWithDataArray:(NSArray *)dataArray rowHeight:(CGFloat)rowHeight
{
    NSInteger  count = dataArray.count;
    CGFloat result = ScreenHeight - count * rowHeight;
    if (result > 5) {
        
        return NO;
    } else {
    
        return YES;
    }

}


@end
